package secondStage.part2.多态.one;

/**
 * @ClassName: [AnimalDemo]
 * @Description: 多态案例
 * @Author: [黄劲松]
 * @CreateDate: [2021-03-14]
 * @Version: [v1.0]
 */
public class AnimalDemo {
    public static void main(String[] args) {
        //有父类引用指向子类对象
        Animal a = new Cat();
        System.out.println(a.age);//运行是看创建对象的左边，运行的内容是父类
//        System.out.println(a.weight);//报错，编译是看创建对象的左边
        a.eat();//成员方法运行看创建对象的右边
//        a.playGame();//报错，成员方法编译是看创建对象的左边

        AnimalOperator ao = new AnimalOperator();//创建动物操作类对象，通用方法
        Cat cat = new Cat();
        ao.useAnimal(cat);
        Dog dog = new Dog();
        ao.useAnimal(dog);
        Pig p = new Pig();
        ao.useAnimal(p);

    }
}
